package com.shanghaionstar.activity.webview.handler;


import android.content.Context;
import android.os.Bundle;
import android.os.Message;
import android.text.TextUtils;
import android.webkit.WebView;

/**
 * Created by Rengui Lu on 2017/3/3.
 */
public class DriverBehaviorWebHandler extends ShareReportWebHandler {

    public DriverBehaviorWebHandler(Context context) {
        super(context);
    }

    @Override
    public void handMsg(Message msg) {
        switch (msg.what) {
            case IWebType.TYPE_DRIVER_BEHAVIOR:
                addFirstInfo(msg);
                break;
            case IWebType.TYPE_ON_PAGE_FINISHED:
                setTitleOnPageFinished();
                break;
        }
    }

    private void setTitleOnPageFinished() {
        CommonWebViewActivity mActivity;
        if (context instanceof CommonWebViewActivity) {
            mActivity = (CommonWebViewActivity) context;
            WebView view = mActivity.getWebview();
            String title = view.getTitle();
            if (!TextUtils.isEmpty(title))
                mActivity.getTop_layout().setTopTitle(title);
        }
    }

    private void addFirstInfo(Message msg) {
        CommonWebViewActivity mActivity;
        if (context instanceof CommonWebViewActivity) {
            mActivity = (CommonWebViewActivity) context;
            Bundle bundle = mActivity.getBundle();
            String isFirstInfo = bundle.getString("firstInfo") == null?"":bundle.getString("firstInfo");
            dataEntity = (WebDataEntity) msg.obj;
//            WebDataEntity entity = (WebDataEntity) msg.obj;
            dataEntity.setLinkUrl(dataEntity.getLinkUrl() + "?isFirstInfo=" + isFirstInfo.toUpperCase());
            webView = mActivity.getWebview();
            webView.loadUrl(dataEntity.getLinkUrl());

//            registerHandler(mActivity.getTop_layout());
        }
    }


}
